package com.zx.inf.sys.controller;

import com.zx.inf.sys.conf.DataSourceContextHolder;
import com.zx.inf.sys.conf.DataSourceInit;
import com.zx.inf.sys.entity.InfDsInfo;
import com.zx.inf.sys.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//2024-7-23
@RestController
@RequestMapping("/datasources")
public class DataSourceController {

    @Autowired
    private DataSourceService dataSourceService;
    @Autowired
    private DataSourceInit dataSourceInit;

    @PostMapping("/add")
    public ResponseEntity<String> addDataSource(@RequestBody InfDsInfo infDsInfo) {
        int count = dataSourceService.addDataSource(infDsInfo);
        if(count>0){
            dataSourceInit.loadAllDataSource();
        }
        return ResponseEntity.ok("DataSource added successfully");
    }

    // 其他如删除数据源等操作...
}
